package gui;

import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.net.URL;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * @author Ramy Refky 
 * */
public class ActionPanel extends JPanel implements MouseListener{

	private static final long serialVersionUID = 1L;
	
	URL  actionSelectSelectedURL= getClass().getResource("graphics/actionPanelGraphics/actionSelectSelected.png");
	URL  actionSelectNotSelectedURL= getClass().getResource("graphics/actionPanelGraphics/actionSelectNotSelected.png");
	URL  zoomInSelectedURL= getClass().getResource("graphics/actionPanelGraphics/zoomInSelected.png");
	URL  zoomInNotSelectedURL= getClass().getResource("graphics/actionPanelGraphics/zoomInNotSelected.png");
	URL  zoomOutSelectedURL= getClass().getResource("graphics/actionPanelGraphics/zoomOutSelected.png");
	URL  zoomOutNotSelectedURL= getClass().getResource("graphics/actionPanelGraphics/zoomOutNotSelected.png");
	URL  printNotSelectedURL= getClass().getResource("graphics/actionPanelGraphics/printNotSelected.png");
	URL  moveWireSelectedURL= getClass().getResource("graphics/actionPanelGraphics/moveWireSelected.png");
	URL  moveWireNotSelectedURL= getClass().getResource("graphics/actionPanelGraphics/moveWireNotSelected.png");
	URL  actionDeleteSelectedURL= getClass().getResource("graphics/actionPanelGraphics/actionDeleteSelected.png");
	URL  actionDeleteNotSelectedURL= getClass().getResource("graphics/actionPanelGraphics/actionDeleteNotSelected.png");
	
	
	ImageIcon actionSelectSelectedImageIcon = new ImageIcon(actionSelectSelectedURL);
	ImageIcon actionSelectNotSelectedImageIcon = new ImageIcon(actionSelectNotSelectedURL);
	ImageIcon zoomInSelectedImageIcon = new ImageIcon(zoomInSelectedURL);
	ImageIcon zoomInNotSelectedImageIcon = new ImageIcon(zoomInNotSelectedURL);
	ImageIcon zoomOutSelectedImageIcon = new ImageIcon(zoomOutSelectedURL);
	ImageIcon zoomOutNotSelectedImageIcon = new ImageIcon(zoomOutNotSelectedURL);
	ImageIcon printNotSelectedImageIcon = new ImageIcon(printNotSelectedURL);
	ImageIcon moveWireSelectedImageIcon = new ImageIcon(moveWireSelectedURL);
	ImageIcon moveWireNotSelectedImageIcon = new ImageIcon(moveWireNotSelectedURL);
	ImageIcon actionDeleteSelectedImageIcon = new ImageIcon(actionDeleteSelectedURL);
	ImageIcon actionDeleteNotSelectedImageIcon = new ImageIcon(actionDeleteNotSelectedURL);
	
	JLabel actionSelectSelectedLabel;
	JLabel actionSelectNotSelectedLabel;
	JLabel zoomInSelectedLabel;
	JLabel zoomInNotSelectedLabel;
	JLabel zoomOutSelectedLabel;
	JLabel zoomOutNotSelectedLabel;
	JLabel printNotSelectedLabel;
	JLabel moveWireSelectedLabel;
	JLabel moveWireNotSelectedLabel;
	JLabel actionDeleteSelectedLabel;
	JLabel actionDeleteNotSelectedLabel;
	
	
	MainGui mg;
	
	/**
	 * Constructor initializes ActionPanel buttons
	 * @param MainGui
	 * */
	public ActionPanel(MainGui mg){
		
		this.mg=mg;
		
		setBounds(5,50,65,500);
		this.setBackground(Color.gray);
		setBorder(BorderFactory.createLineBorder(Color.black,2));
		setVisible(true);
		setLayout(null);
		
		actionSelectSelectedLabel = new JLabel(actionSelectSelectedImageIcon);
		actionSelectSelectedLabel.setBounds(5,5,58,59);
		actionSelectSelectedLabel.setVisible(true);
		this.add(actionSelectSelectedLabel);
		
		actionSelectNotSelectedLabel = new JLabel(actionSelectNotSelectedImageIcon);
		actionSelectNotSelectedLabel.setBounds(5,5,58,59);
		actionSelectNotSelectedLabel.setVisible(false);
		actionSelectNotSelectedLabel.addMouseListener(this);
		this.add(actionSelectNotSelectedLabel);
		
		moveWireSelectedLabel = new JLabel(moveWireSelectedImageIcon);
		moveWireSelectedLabel.setBounds(5,65,58,59);
		moveWireSelectedLabel.setVisible(false);
		this.add(moveWireSelectedLabel);
		
		moveWireNotSelectedLabel = new JLabel(moveWireNotSelectedImageIcon);
		moveWireNotSelectedLabel.setBounds(5,65,58,59);
		moveWireNotSelectedLabel.setVisible(true);
		moveWireNotSelectedLabel.addMouseListener(this);
		this.add(moveWireNotSelectedLabel);
		
		actionDeleteSelectedLabel = new JLabel(actionDeleteSelectedImageIcon);
		actionDeleteSelectedLabel.setBounds(5,125,58,59);
		actionDeleteSelectedLabel.setVisible(false);
		this.add(actionDeleteSelectedLabel);
		
		actionDeleteNotSelectedLabel = new JLabel(actionDeleteNotSelectedImageIcon);
		actionDeleteNotSelectedLabel.setBounds(5,125,58,59);
		actionDeleteNotSelectedLabel.setVisible(true);
		actionDeleteNotSelectedLabel.addMouseListener(this);
		this.add(actionDeleteNotSelectedLabel);
		
		zoomInSelectedLabel = new JLabel(zoomInSelectedImageIcon);
		zoomInSelectedLabel.setBounds(5,185,58,59);
		zoomInSelectedLabel.setVisible(false);
		this.add(zoomInSelectedLabel);
		
		zoomInNotSelectedLabel = new JLabel(zoomInNotSelectedImageIcon);
		zoomInNotSelectedLabel.setBounds(5,185,58,59);
		zoomInNotSelectedLabel.setVisible(true);
		zoomInNotSelectedLabel.addMouseListener(this);
		this.add(zoomInNotSelectedLabel);
		
		zoomOutSelectedLabel = new JLabel(zoomOutSelectedImageIcon);
		zoomOutSelectedLabel.setBounds(5,245,58,59);
		zoomOutSelectedLabel.setVisible(false);
		this.add(zoomOutSelectedLabel);
		
		zoomOutNotSelectedLabel = new JLabel(zoomOutNotSelectedImageIcon);
		zoomOutNotSelectedLabel.setBounds(5,245,58,59);
		zoomOutNotSelectedLabel.setVisible(true);
		zoomOutNotSelectedLabel.addMouseListener(this);
		this.add(zoomOutNotSelectedLabel);
		
		printNotSelectedLabel = new JLabel(printNotSelectedImageIcon);
		printNotSelectedLabel.setBounds(5,305,58,59);
		printNotSelectedLabel.setVisible(true);
		printNotSelectedLabel.addMouseListener(this);
		this.add(printNotSelectedLabel);
		
		repaint();
		validate();
	}
	/**
	 * Sets all ActionPanel buttons to appear not selected.
	 * */
	public void loseFocus(){
		actionSelectSelectedLabel.setVisible(false);
		actionSelectNotSelectedLabel.setVisible(true);
		zoomInSelectedLabel.setVisible(false);
		zoomInNotSelectedLabel.setVisible(true);
		zoomOutSelectedLabel.setVisible(false);
		zoomOutNotSelectedLabel.setVisible(true);
		moveWireSelectedLabel.setVisible(false);
		moveWireNotSelectedLabel.setVisible(true);
		actionDeleteSelectedLabel.setVisible(false);
		actionDeleteNotSelectedLabel.setVisible(true);
	}
	@Override
	public void mousePressed(MouseEvent e) {
		
		mg.getAboutPanel().setVisible(false);
		
		if(e.getSource()==actionSelectNotSelectedLabel){
			
			actionSelectSelectedLabel.setVisible(true);
			actionSelectNotSelectedLabel.setVisible(false);
			zoomInSelectedLabel.setVisible(false);
			zoomInNotSelectedLabel.setVisible(true);
			zoomOutSelectedLabel.setVisible(false);
			zoomOutNotSelectedLabel.setVisible(true);
			moveWireSelectedLabel.setVisible(false);
			moveWireNotSelectedLabel.setVisible(true);
			actionDeleteSelectedLabel.setVisible(false);
			actionDeleteNotSelectedLabel.setVisible(true);
			
			mg.getActions().setActionToSelect();
			mg.getComponentPanel().loseFocus();
		}
		if(e.getSource()==moveWireNotSelectedLabel){
			
			actionSelectSelectedLabel.setVisible(false);
			actionSelectNotSelectedLabel.setVisible(true);
			zoomInSelectedLabel.setVisible(false);
			zoomInNotSelectedLabel.setVisible(true);
			zoomOutSelectedLabel.setVisible(false);
			zoomOutNotSelectedLabel.setVisible(true);
			moveWireSelectedLabel.setVisible(true);
			moveWireNotSelectedLabel.setVisible(false);
			actionDeleteSelectedLabel.setVisible(false);
			actionDeleteNotSelectedLabel.setVisible(true);
			
			mg.getActions().setActionToMoveWire();
			mg.getComponentPanel().loseFocus();
			mg.getWorkArea().hideSelectionBox();
			mg.getWorkArea().deselectAllComponents();
		}
		if(e.getSource()==actionDeleteNotSelectedLabel){
			
			actionSelectSelectedLabel.setVisible(false);
			actionSelectNotSelectedLabel.setVisible(true);
			zoomInSelectedLabel.setVisible(false);
			zoomInNotSelectedLabel.setVisible(true);
			zoomOutSelectedLabel.setVisible(false);
			zoomOutNotSelectedLabel.setVisible(true);
			moveWireSelectedLabel.setVisible(false);
			moveWireNotSelectedLabel.setVisible(true);
			actionDeleteSelectedLabel.setVisible(true);
			actionDeleteNotSelectedLabel.setVisible(false);
			
			mg.getActions().setActionToDelete();
			mg.getComponentPanel().loseFocus();
			mg.getWorkArea().hideSelectionBox();
			mg.getWorkArea().deselectAllComponents();
		}
		
		if(e.getSource()==zoomInNotSelectedLabel){
			
			actionSelectSelectedLabel.setVisible(false);
			actionSelectNotSelectedLabel.setVisible(true);
			zoomInSelectedLabel.setVisible(true);
			zoomInNotSelectedLabel.setVisible(false);
			zoomOutSelectedLabel.setVisible(false);
			zoomOutNotSelectedLabel.setVisible(true);
			moveWireSelectedLabel.setVisible(false);
			moveWireNotSelectedLabel.setVisible(true);
			actionDeleteSelectedLabel.setVisible(false);
			actionDeleteNotSelectedLabel.setVisible(true);
			
			mg.getActions().setActionToZoomIn();
			mg.getComponentPanel().loseFocus();
		}
		if(e.getSource()==zoomOutNotSelectedLabel){
			
			actionSelectSelectedLabel.setVisible(false);
			actionSelectNotSelectedLabel.setVisible(true);
			zoomInSelectedLabel.setVisible(false);
			zoomInNotSelectedLabel.setVisible(true);
			zoomOutSelectedLabel.setVisible(true);
			zoomOutNotSelectedLabel.setVisible(false);
			moveWireSelectedLabel.setVisible(false);
			moveWireNotSelectedLabel.setVisible(true);
			actionDeleteSelectedLabel.setVisible(false);
			actionDeleteNotSelectedLabel.setVisible(true);
			
			mg.getActions().setActionToZoomOut();
			mg.getComponentPanel().loseFocus();
		}
		
		if(e.getSource()==printNotSelectedLabel){
			mg.getWorkArea().drawImage();
		}
	}
	@Override
	public void mouseClicked(MouseEvent e) {}
	@Override
	public void mouseEntered(MouseEvent e) {}
	@Override
	public void mouseExited(MouseEvent e) {}
	@Override
	public void mouseReleased(MouseEvent e) {}
}